<section class="content-header" >
    <h1>
        车辆管理
        <small>车辆列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="{:U('/Admin/index')}"><i class="fa fa-home"></i>首页</a></li>
        <li class="active">车辆管理</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="box-title"><label >车辆列表</label></div>
                    <div class="pull-right">
                        <button class="btn btn-block btn-primary btn-sm" onclick="addCar()"><i class="fa fa-plus"></i>&nbsp;&nbsp;&nbsp;添加车辆</button>
                    </div>
                </div><!-- /.box-header -->
                <div class="box-body">
                    <table id="table" class="table table-bordered table-striped" width="100%">
                        <thead>
                            <tr>
                                <th>联系人</th>
                                <th>站点</th>
                                <th>方量</th>
                                <th>车号</th>
                                <th>联系电话</th>
                                <th>创建时间</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                    </table>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</section><!-- /.content -->
<!-- DATA TABES SCRIPT -->
<!-- page script -->
<script type="text/javascript">
    $(function () {
        $('#table').dataTable({
            "autoWidth": true,
//            "order": [4,'desc'],
            "processing": true, //载入数据的时候是否显示“载入中”
            'ordering': false, //排序操作在服务端进行，所以可以关了。
            'serverSide': true,
            "searching": false,
            "ajax": {
                "url": "{:U('Car/mgr')}",
                "type": "POST"
            },
            "columns": [
                {"data": "name"},
                {"data": "sitename"},
                {"data": "load"},
                {"data": "carno"},
                {"data": "mobile"},
                {"data": "addtime"},
                {"data": "status"},
                {"data": "id"}
            ],
            "columnDefs": [
                {
                    "targets": 0,
                    "render": function (data, type, row) {

                        return data+"<br/>最后上线时间:"+row['onlines'];
                    }
                },
                {
                    "targets": 6,
                    "render": function (data, type, row) {
                        var html =  data==0?'启用':"<span style='color: red;'>停用</span>";
                        if(row.cstatus!=null){
                            html+="<br/><span style='color:red'>任务中</span>";
                        }
                        var work = ['','<span style="color: green;">待命</span>','<span style="color: red;">已收车</span>','<span style="color: red;">检修</span>'];
                        html+="<br/>"+work[row.work_status];
                        return html;
                    }
                },
                {
                    "targets": 7,
                    "render": function (data, type, row) {
                        return '<a href="javascript:uptateItem(' +data + ')"><i class="fa fa-edit"></i>&nbsp;编辑</a>';
                    }
                }
             ],
            "language": lang
        });
    });

    function uptateItem(id) {
        var url = "{:U('car/add')}";
        url += url.indexOf('?') != -1 ? '&id=' + id : '?id=' + id;
        $.dialog(url, '修改车辆信息', null);
    }


    function addCar() {
        $.dialog("{:U('car/add')}", '添加车辆');
    }
</script>